<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2023-08-31 11:00:35
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description:   :gridOps="gridOptions" other
-->

<template>
	<sc-VxeTable ref="xGrid" :gridEvts="gridEvents" :gridOps="gridOps" :tablecode="'pro_pot_index'"
		:url="api.pro.pot.list" :params="{ is_kk: 1 }">
	</sc-VxeTable>

	<save-dig v-if="dialog.save" ref="save" @success="handleSuccess" @closed="dialog.save = false"></save-dig>
	<add-raw v-if="dialog.raw" ref="raw" @success="handleSuccess" @closed="dialog.raw = false"></add-raw>
	<edit-raw v-if="dialog.editraw" ref="editraw" @success="handleSuccess" @closed="dialog.editraw = false"></edit-raw>
	<process-swipe v-if="dialog.process" ref="swipe" @success="handleSuccess" @closed="dialog.process = false">
	</process-swipe>
	<verify-list v-if="dialog.verify" ref="verify" @success="handleSuccess" @closed="dialog.verify = false">
	</verify-list>
	<repairDig v-if="dialog.repair" ref="repair" @success="handleSuccess" @closed="dialog.repair = false">
	</repairDig>
</template>

<script>
export default {
	name: "pro_pot_index",
};
</script>

<script setup>
// import { useRouter } from "vue-router";
import { nextTick, ref } from "vue";
// , onMounted, reactive, ref
// const router = useRouter();
import { ElMessageBox } from "element-plus";
import saveDig from "./save";
import repairDig from "./repair";
import ProcessSwipe from "./ProcessSwipe";
import addRaw from "./addRaw";
import editRaw from "./editRaw";
import verifyList from "./verifyList";
import api from "@/api";
import tool from "@/utils/tool";
const dialog = ref({
	process: false,
	raw: false,
	editraw: false,
	verify: false,
	save: false,
	repair: false,
});
const xGrid = ref({});
const swipe = ref({});
const raw = ref({});
const editraw = ref({});
const verify = ref({});
const repair = ref({});
const save = ref({});
const handleSuccess = () => {
	xGrid.value.refresh();
};
const gridOps = {
	columns: [
		{
			field: "company_name",
			className: "red",
		},
		{
			field: "process.name",
			className: "red",
		},
		{
			field: "material.name",
			className: "blue",
		},
	],
	rowClassName: ({ row }) => {
		let time = new Date(row.potdate).getTime();
		let nowtime = new Date(tool.SYS_DATE()).getTime();
		if (time == nowtime)
			return 'backgroudYellow'
	}
};
const gridEvents = {

	cellDblclick: function ({ row }) {
		dialog.value.save = true;
		nextTick(() => {
			save.value.setData(row, false).open();
		});
	},
	ProcessSwipe: ({ button }) => {
		dialog.value.process = true;
		nextTick(() => {
			swipe.value.setData(button.selectRecords[0]).open();
		});
	},
	repair: ({ button }) => {
		dialog.value.repair = true;
		nextTick(() => {
			repair.value
				.setData(button.selectRecords[0], button.selectRecords)
				.open();
		});
	},
	addRaw: ({ button }) => {
		dialog.value.raw = true;
		nextTick(() => {
			raw.value.setData(button.selectRecords[0]).open();
		});
	},
	editRaw: ({ button }) => {
		ElMessageBox.confirm("您确定要编辑大货配方?", "警告", {
			type: "warning",
			center: true,
		})
			.then((type) => {
				if (type === "confirm") {
					dialog.value.editraw = true;
					nextTick(() => {
						editraw.value.setData(button.selectRecords[0]).open();
					});
				}
			})
			.catch(() => { });
	},
	verifyList: ({ button }) => {
		dialog.value.verify = true;
		nextTick(() => {
			verify.value.setData(button.selectRecords[0]).open();
		});
	},
	nosaveDyePlan: ({ button }) => {
		return ElMessageBox.confirm(
			"您确定要退回开卡?"
		).then((type) => {
			if (type === "confirm") {
				return api.pro.pot.nosaveDyePlan.post({ ids: button.selectRecords.map((v) => v.id) });
			}
		})
	},
};
</script>
